package com.dsg.controller.approve;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsg.common.constants.MessageConstants;
import com.dsg.common.dto.AjaxResult;
import com.dsg.controller.base.BaseController;
import com.dsg.entity.approve.DsgApproveTask;
import com.dsg.service.approve.IDsgApproveTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 任務配置表 前端控制器
 * </p>
 *
 * @author system
 * @since 2020-07-04
 */
@RestController
@RequestMapping("/approve/dsgApproveTask")
@Slf4j
@Api(description = "任務配置表")
public class DsgApproveTaskController extends BaseController {

    @Autowired
    private IDsgApproveTaskService service;

    /**
     * 實例動態表下拉
     *
     * @return
     */
    @GetMapping(value = "/listTask")
    @ApiOperation("實例動態表下拉")
    public AjaxResult listTask() {
        QueryWrapper<DsgApproveTask> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("GROUP_CONCAT(NODE_ID) as nodeId,TASK_NAME as taskName");
        queryWrapper.eq("ENT_CODE", getEntCode());
        queryWrapper.groupBy("TASK_NAME");
        List<DsgApproveTask> taskList = service.list(queryWrapper);
        // 格式要返回的数据
        AjaxResult ajaxResult = json(MessageConstants.SSO_STATUS_SUCCESS, taskList);
        return ajaxResult;
    }

}
